package org.ftc.util;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import org.springframework.web.context.ServletConfigAware;

public class AppInit implements ServletConfigAware{ 
	
	public void setImagePath( String imagePath){
		Global.APP.IMAGE_PATH = imagePath;
		if( !new File(Global.APP.IMAGE_PATH).isDirectory() )
			new File(Global.APP.IMAGE_PATH).mkdirs();  
	}
	
	public void setReportPath( String reportPath){
		Global.APP.REPORT_PATH = reportPath;
	}
	public void setServletConfig(ServletConfig config) {
		// TODO Auto-generated method stub
		ServletContext app = config.getServletContext();
		if( Global.APP.HOME_PATH == null )
			Global.APP.HOME_PATH = app.getRealPath(File.separator);
		if( Global.APP.CONFIG_PATH == null )
			Global.APP.CONFIG_PATH = Global.APP.HOME_PATH + "WEB-INF";
		if( Global.APP.SERVER_NAME == null )
			Global.APP.SERVER_NAME = app.getServletContextName();
		if( Global.APP.SERVER_INFO == null ) 
			Global.APP.SERVER_INFO = app.getServerInfo();
		
		if( Global.APP.FONT_KAIU == null )
			Global.APP.FONT_KAIU = Global.APP.CONFIG_PATH + File.separator + "font" + File.separator + "kaiu.ttf";
	}

}
